const isEnglish = navigator.language.startsWith('en');

webpackJsonp(
  [2],
  [
    ,
    ,
    ,
    ,
    function (e, t, n) {
      e.exports = n(5);
    },
    function (e, t, n) {
      "use strict";
      n(6);

      (function () {
        // 获取相关 DOM 元素
        const hintElement = document.querySelector(".hint");
        const downloadButtons = document.querySelectorAll(".download-btn");

        const userAgent = navigator.userAgent;
        const isMac = /Mac OS X/.test(userAgent);
        const isWeChat = /MicroMessenger/i.test(userAgent);

        // 根据不同条件修改按钮状态
        function updateButtonState() {
          downloadButtons.forEach((button) => {
            const { android, ios, iosenterprise, type } = button.dataset;
            let downloadLink = '';

            // 设置下载链接，根据操作系统来决定
            if (isMac) {
              downloadLink = type === "beta" ? iosenterprise : ios;
            } else {
              downloadLink = android;
            }

            // 如果没有找到链接，设置灰色按钮
            if (!downloadLink) {
              button.classList.add("download-btn-gray");
            }
          });
        }

        // 为每个下载按钮添加点击事件
        downloadButtons.forEach((button) => {
          button.addEventListener("click", (e) => {
            e.preventDefault();

            const { android, ios, iosenterprise, schema, type } = button.dataset;
            let redirectUrl = '';

            // 判断是否为微信环境
            if (isWeChat) {
              hintElement.style.height = isEnglish ? "6.5em" : "5em";
              return;
            }

            // 根据设备系统和类型设置下载链接
            if (isMac) {
              redirectUrl = type === "beta" ? iosenterprise : ios;
            } else {
              redirectUrl = android;
            }

            // 如果有 schema，尝试打开 app
            if (type !== "beta" && schema) {
              const iframe = document.createElement("iframe");
              iframe.style.display = "none";
              iframe.src = `${schema}://`;
              document.body.appendChild(iframe);
            }

            // 执行跳转
            if (redirectUrl) {
              location.href = redirectUrl;
            }
          });
        });

        // 初始化按钮状态
        updateButtonState();

        // 监听窗口调整事件
        window.addEventListener("resize", updateButtonState);
      })();
    },
    function (e, t) {},
  ],
  [4]
);
